import edge_tts
from datetime import datetime
from uuid import uuid4

# zh-CN-XiaoxiaoNeural  Female  News, Novel     Warm
# zh-CN-XiaoyiNeural    Female  Cartoon, Novel  Lively
# zh-CN-YunjianNeural   Male    Sports, Novel   Passion
# zh-CN-YunxiNeural     Male    Novel           Lively, Sunshine
# zh-CN-YunxiaNeural    Male    Cartoon, Novel  Cute
# zh-CN-YunyangNeural   Male    News            Professional, Reliable
_voice = "zh-CN-XiaoxiaoNeural"


async def text_to_speech(text: str):
    communicate = edge_tts.Communicate(text, _voice)
    result: bytes | None = None
    async for message in communicate.stream():
        if message["type"] == "audio":
            b = message["data"]
            if result is None:
                result = b
            else:
                result += b
    return result
